package rules

import (
	v1 "golang-sgg-daijia/api/v1"
)

// RewardRuleImplement 计算费用
type RewardRuleImplement struct {
}

func NewRewardRuleImplement() *RewardRuleImplement {
	return &RewardRuleImplement{}
}

// CalculateAllReward 计算费用的步骤
func (f *RewardRuleImplement) CalculateAllReward(feeRuleReq *v1.RewardRuleRequestForm) *v1.RewardRuleResponse {
	resp := new(v1.RewardRuleResponse)
	orderNum := feeRuleReq.OrderNum
	// todo 如果有多种奖励，由注册的方式串联起来F
	newOrderNumRewardRule(orderNum).CalculateReward(feeRuleReq, resp)
	return resp
}

type RewardRule interface {
	CalculateReward(feeRuleReq *v1.RewardRuleRequestForm, feeRuleResp *v1.RewardRuleResponse)
}

func newOrderNumRewardRule(orderNum int) RewardRule {
	if orderNum > 5 {
		return &orderNum5RewardRule{}
	} else if orderNum > 10{
		return &orderNum10RewardRule{}
	}
	return &defaultOrderNumRewardRule{}
}

type orderNum5RewardRule struct{}

func (s *orderNum5RewardRule) CalculateReward(feeRuleReq *v1.RewardRuleRequestForm, feeRuleResp *v1.RewardRuleResponse) {
	feeRuleResp.RewardAmount = 5
}

type orderNum10RewardRule struct{}

func (s *orderNum10RewardRule) CalculateReward(feeRuleReq *v1.RewardRuleRequestForm, feeRuleResp *v1.RewardRuleResponse) {
	feeRuleResp.RewardAmount = 2
}

type defaultOrderNumRewardRule struct{}

func (s *defaultOrderNumRewardRule) CalculateReward(feeRuleReq *v1.RewardRuleRequestForm, feeRuleResp *v1.RewardRuleResponse) {

}